package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Course;
import com.hs.sfzy.entity.Question;
import com.hs.sfzy.service.CourseService;
import com.hs.sfzy.service.QuestionService;
import com.hs.sfzy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: sfzyBackEnd
 * @BelongsPackage: com.hs.sfzy.controller
 * @ClassName QuestionController
 * @Author: 陈千鱼不是鱼
 * @CreateTime: 2024-10-24  17:50
 * @Description: 问题表控制层
 * @Version: 1.0
 */
@RestController
@RequestMapping("/question")
@Api(tags = "问题")
@RequiredArgsConstructor
public class QuestionController {

    private final QuestionService questionService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result page(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "5") Integer pageSize,
            @ApiParam("心理知识名字") String title
    ) {
        PageInfo<Question> info = questionService.page(pageNum,pageSize,title);

        return Result.success(info);
    }

    @GetMapping("/pageforwx")
//    @ApiOperation("分页查询")
    public Result pageForWx(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "5") Integer pageSize,
            Question question
    ) {
        PageInfo<Question> info = questionService.pageForWx(pageNum,pageSize,question);

        return Result.success(info);
    }

    @PostMapping("/save")
    @ApiOperation("新增问题")
    public Result save(@RequestBody Question question) {
        questionService.save(question);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除问题")
    public Result deleteById(@PathVariable("id") Integer id) {
        questionService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("更新问题")
    public Result update(@RequestBody Question question) {
        questionService.update(question);
        return Result.success();
    }

    @GetMapping("findAllIDAndTitle")
    @ApiOperation("查询全部")
    public Result findAllIDAndTitle() {
        List<Question> questionList  =  questionService.findAllIDAndTitle();
        return Result.success(questionList);
    }

}
